package com.util;

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;

import javax.imageio.ImageIO;

import com.image.util.ImageUtils;
import com.image.util.ImgCompress;

import net.sf.json.JSONObject;
public class IceTest {
	
	public static String access_token(){
		String accessToken="";
		String GET_URL="https://openapi.colourlife.com/v1/authms/auth/app?ts=1514512059"
				+ "&corp_uuid=a8c58297436f433787725a94f780a3c9"
				+ "&app_uuid=ICEEANQUAN-ADC5-42B8-BB2E-BC39B211FDED"
				+ "&signature=dfda1da6ddcba5e0d5301dff6ea61a3c"
				+ "&timestamp=1514512059"
				+ "&sign=ab898f60038dada455d4e40e0ceec82c"
				+ "&appID=ICEEANQUAN-ADC5-42B8-BB2E-BC39B211FDED";
		try {
			URL url = new URL(GET_URL);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
	        connection.setRequestMethod("POST");  
	        connection.connect();
	        BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));  
	        String line;  
	        StringBuilder sb = new StringBuilder();  
	        while ((line = br.readLine()) != null) {
	            sb.append(line);  
	        }  
	        br.close();
	        connection.disconnect();
	        new JSONObject();
			JSONObject json=JSONObject.fromObject(sb.toString());
			JSONObject content = json.getJSONObject("content");
			accessToken = content.getString("accessToken");
			System.out.println("accessToken"+accessToken);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return accessToken;
	}
	
	public static void main(String[] args) throws IOException{
		DataUtil d=new DataUtil();
		//图片压缩
        ImgCompress.setFile("G:/image/copy/2018010712571101.png");			
        System.out.println("开始：" + d.data());
        ImgCompress imgCom = new ImgCompress("G:/image/copy/2018010712571101.png");  
        imgCom.resizeFix(400, 400); 
        System.out.println("结束：" + d.data());
		File currentImg = new File("G:/image/copy/2018010712571101.png");			//当前图片
        File rotateImg = new File("G:/image/copy/2018010712571101.png");  		//旋转后保存图片
        BufferedImage image = ImageIO.read(currentImg);  
        //旋转
        image=ImageUtils.rotateCounterclockwise90(image);
        ImageIO.write(image, "png", rotateImg);
        //水平翻转  
        image=ImageUtils.rotateHorizon(image);
        ImageIO.write(image, "png", rotateImg);
        
	}
}
